<?php
namespace app\common\model;
class Tasked extends Base{
    function source(){
    	return $this->belongsTo('source');
    }
    function media(){
    	return $this->belongsToMany('media','task_media','media_id','task_id');
    }
    function getTask($where=[],$page=0,$option=[]){
        $field=isset($option['field'])?$option['field']:"*";
        $with=isset($option['with'])?$option['with']:[];
    	$with=array_merge($with,['media','source','source.media']);
        $options=[
            'field'=>$field,
            'with'=>$with,
        ];
    	$list=$this->readAll($where,$page,$options);
        foreach($list as $k => $v){
        	if(!empty($v['source'])){
        		if(!$v['msg'])$v['msg']=$v['source']['content'];
        		if(!empty($v['source']['media'])&&empty($v['media'])){
        			$v['media']=$v['source']['media'];
        		}
        		unset($v['source']);
                $list[$k]=$v;
        	}
        }
    	return $list;
    }
}
